home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / SQL Format252808242001.psc / General.bas < prev    next >
Encoding:
BASIC Source File  |  2001-08-24  |  2.5 KB  |  104 lines

  1. Attribute VB_Name = "modGeneral"
  2. Option Explicit
  3. Public gastrClause()                              As String
  4.  
  5. Public Function GetWord(S, Indx As Integer, SPos As Integer)
  6. '
  7. ' Extracts a word in text where words are separated by 1 or more spaces.
  8. ' SPos - Returns the start position of the word.
  9. Dim i As Integer, WC As Integer, Count As Integer, EPos As Integer, OnASpace As Integer
  10.   WC = CountWords(S)
  11.   If Indx < 1 Or Indx > WC Then
  12.     GetWord = Null
  13.     Exit Function
  14.   End If
  15.   Count = 0
  16.   OnASpace = True
  17.   For i = 1 To Len(S)
  18.     If Mid(S, i, 1) = " " Then
  19.       OnASpace = True
  20.     Else
  21.       If OnASpace Then
  22.         OnASpace = False
  23.         Count = Count + 1
  24.         If Count = Indx Then
  25.           SPos = i
  26.           Exit For
  27.         End If
  28.       End If
  29.     End If
  30.   Next i
  31.   EPos = InStr(SPos, S, " ") - 1
  32.   If EPos <= 0 Then EPos = Len(S)
  33.   GetWord = Mid(S, SPos, EPos - SPos + 1)
  34. End Function
  35.  
  36.  
  37. Public Function CountWords(S) As Integer
  38. '
  39. ' Counts words in a string separated by 1 or more spaces
  40. '
  41. Dim WC As Integer, i As Integer, OnASpace As Integer
  42.   If VarType(S) <> 8 Or Len(Trim(S)) = 0 Then
  43.     CountWords = 0
  44.     Exit Function
  45.   End If
  46.   WC = 0
  47.   OnASpace = True
  48.   For i = 1 To Len(S)
  49.     If Mid(S, i, 1) = " " Then
  50.       OnASpace = True
  51.     Else
  52.       If OnASpace Then
  53.         OnASpace = False
  54.         WC = WC + 1
  55.       End If
  56.     End If
  57.   Next i
  58.   CountWords = WC
  59. End Function
  60.  
  61. Public Function ReadFileIntoArray(strFileName As String) As Boolean
  62. '---------------------------------------------------------------------------------------------------------------------------
  63. 'Purpose    :Takes a file and reads into an array.
  64. 'Parameters :
  65. ' [strFileName] File name to be read into array.
  66. ' [lngNumberOfRecords] Returns the number of records in the file.
  67. 'Returns    :
  68. 'Created By :Gregor L. Brown
  69. 'Created On :02.01.2001 16:06.31
  70. 'Comments   :
  71. '---------------------------------------------------------------------------------------------------------------------------
  72.  
  73. Dim lngN                      As Long
  74. Dim lngFileNum                As Long
  75.  
  76. ReadFileIntoArray = False
  77.  
  78. 'Set up the variables.
  79. lngN = 0
  80. lngFileNum = FreeFile()
  81.  
  82. 'Open text file.
  83. Open strFileName For Input As #lngFileNum
  84.  
  85. 'Loop thru each line.
  86. Do Until EOF(lngFileNum)
  87.     
  88.   ReDim Preserve gastrClause(0 To lngN)
  89.   Input #lngFileNum, gastrClause(lngN)
  90.   
  91.   lngN = lngN + 1
  92.  
  93. Loop
  94.  
  95. 'Close out file
  96. Close #lngFileNum
  97.  
  98. ReadFileIntoArray = True
  99.  
  100. End Function
  101.  
  102.  
  103.  
  104.